<?php

namespace common\modules\article\models\backend;

use common\traits\TreeModelTrait;
use Yii;
use yii\helpers\ArrayHelper;

/**
 * CategoryTree represents the model behind the tree form about `common\modules\article\models\backend\Category`.
 */
class CategoryTree extends Category
{

    use TreeModelTrait {
        rules as treeRule;
        behaviors as treeBehaviors;
        attributeLabels as treeAttributeLabels;
    }

    /**
     * @var string
     *
     * the 实现NestedSetQueryBehavior的类名
     * 默认为`kartik\tree\models\TreeQuery`.
     */
    public static $treeQueryClass;

    /**
     * @var bool whether to HTML encode the tree node names. Defaults to `true`.
     */
    public $encodeNodeNames = true;

    /**
     * @var bool whether to HTML purify the tree node icon content before saving.
     * Defaults to `true`.
     */
    public $purifyNodeIcons = true;

    /**
     * @var array activation errors for the node
     */
    public $nodeActivationErrors = [];

    /**
     * @var array node removal errors
     */
    public $nodeRemovalErrors = [];

    /**
     * @var bool attribute to cache the `active` state before a model update. Defaults to `true`.
     */
    public $activeOrig = true;

    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return parent::tableName();
    }

    /**
     * Note overriding isDisabled method is slightly different when
     * using the trait. It uses the alias.
     */
    public function isDisabled()
    {
        return $this->parentIsDisabled();
    }

    /**
     * {@inheritdoc}
     */
    public function behaviors()
    {
        $behaviors = parent::behaviors();
        $behaviors = ArrayHelper::merge($behaviors, $this->treeBehaviors());
        return $behaviors;
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        $attributeLabels = parent::attributeLabels();
        $attributeLabels = ArrayHelper::merge($attributeLabels, $this->treeAttributeLabels());
        return $attributeLabels;
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        $rules = $this->treeRule();
        return $rules;
    }
}
